package com.yjt.javatest.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yjt.javatest.entity.Question;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author fengye
 * @Date: 2022-07-17-14:02
 * @Description:
 */
@Mapper
@Repository
public interface QuestionMapper extends BaseMapper<Question> {


    @Select("select q.* from question q where q.category_id = #{categoryId} and q.user_id = #{userId} and q.is_deleted = 0")
    List<Question> getQuestionsByCategoryId(Integer categoryId,Long userId);
    @Select("select q.question_id, q.user_id, q.type, q.content, q.score from question q where q.category_id = #{categoryId} and q.user_id = #{userId} and q.is_deleted = 0")
    List<Question> getQuestionsByCategoryIdWithoutImage(Integer categoryId,Long userId);

    @Select("select q.* from question q, question_test qt where qt.question_id = q.question_id and qt.test_id = #{testId} and q.is_deleted = 0 order by qt.order")
    List<Question> getQuestionsByTestId(Long testId);

    @Update("update question set category_id = #{newId} where category_id = #{id} and user_id = #{userId}")
    Integer updateCategoryIdByCategoryId(Integer newId, Integer id, Long userId);
}
